package com.molyfun.parents.activity.record.itemview;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.makeramen.roundedimageview.RoundedTransformationBuilder;
import com.molyfun.parents.R;
import com.molyfun.parents.rest.bean.RecordResponse;
import com.squareup.picasso.Transformation;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by william(liuchao.hit@gmail.com).
 * Date:11/3/16.
 *
 * 此类为容器
 */
public class RecordPlaceholderImageView extends BaseRecordView {

    protected LayoutInflater layoutInflater;

    private Context context;

    @InjectView(R.id.record_user)
    TextView mRecordUser;
    @InjectView(R.id.holder_msg)
    TextView mHolderMsg;
    @InjectView(R.id.error_notice)
    ImageView mErrorNotice;

    Transformation transformation = new RoundedTransformationBuilder()
            .borderColor(Color.TRANSPARENT)
            .borderWidthDp(6)
            .oval(false)
            .build();

    public RecordPlaceholderImageView(Context context, AttributeSet attrs, int defStyle) {
        this(context, attrs);
    }

    public RecordPlaceholderImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs);
    }

    public RecordPlaceholderImageView(Context context) {
        super(context);
        init(context, null);
    }

    private void init(Context context, AttributeSet attrs) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        layoutInflater.inflate(R.layout.widget_record_placeholder_image, this);
        ButterKnife.inject(this);
        mErrorNotice.setOnClickListener(this);
    }

    /**
     * init view
     *
     */
    public void initData(RecordResponse.PlaceHolderRecordBean placeHolderRecordBean) {
        if(placeHolderRecordBean != null){
            mRecordBean = placeHolderRecordBean;
            mRecordUser.setText(mRecordBean.getUsername());
            System.out.println("图片显示UI"+mRecordBean.getUsername());
            // 0代表上传中，1代表失败
            if(placeHolderRecordBean.getState() == 0){
                mHolderMsg.setText("上传中,请稍后...");
                mErrorNotice.setVisibility(View.GONE);
            }else if(placeHolderRecordBean.getState() == 1){
                mHolderMsg.setText("上传失败");
                mErrorNotice.setVisibility(View.VISIBLE);
            }

            setOnLongClickListener(this);
        }
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.error_notice:
                if(nRecordOperationCallBack != null){
                    nRecordOperationCallBack.onRecordReUpload(mRecordBean);
                }
                break;
        }
    }

}